# coding=utf-8
"""
每日7:25
cron: 0 25 7 * * ?
new Env("精易论坛")
"""
import urllib
from urllib import parse
import requests
import notify
import time
import re
import random

import utils.tool as TOOL
import utils.getCookie as getCookie

global msg

msg = """
名称|累计|本月|总获得|总精币|状态
:--:|:--:|:--:|:--:|:--:|:--:
"""


def main():
    users = getCookie.GetQlEnvs().getCookies('JYLT_COOKIE')
    print("🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉\n")
    print("获取到: " + str(len(users)) + " 个用户")
    print("-------------------------------------------")

    for user in users:
        signIn(user)


# 签到
def signIn(user):
    global msg
    url = "https://bbs.125.la/plugin.php?id=dsu_paulsign:sign"
    data = 'formhash=926371b6&submit=1&operation=qiandao&qdxq=kx&ajax=1&infloat=0'
    headers = {
        "Host": "bbs.125.la",
        "accept": "*/*",
        "origin": "//bbs.125.la",
        "x-requested-with": "XMLHttpRequest",
        "user-agent": "Mozilla/5.0 (Linux; U; Android 11; zh-cn; M2011K2C Build/RKQ1.200826.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/79.0.3945.147 Mobile Safari/537.36 XiaoMi/MiuiBrowser/14.3.21",
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "sec-fetch-site": "same-origin",
        "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
        "cookie": "lDlk_ecc9_saltkey=gypyB1q2;lDlk_ecc9_lastvisit=1671591615;lDlk_ecc9_con_request_uri=http%3A%2F%2Fbbs.125.la%2Fconnect.php%3Fmod%3Dlogin%26op%3Dcallback%26referer%3Dindex.php;lDlk_ecc9_client_token=AB463AA7680A8BC46D64C58FC637960E;lDlk_ecc9_connect_is_bind=1;lDlk_ecc9_connect_uin=AB463AA7680A8BC46D64C58FC637960E;lDlk_ecc9_nofavfid=1;lDlk_ecc9_lastcheckfeed=662770%7C1672326032;__ancc_token=eDy0p0n5DsQMBJ8B4yxj2Q==;lDlk_ecc9_seccode=507.0542e4feff0318d6c5;lDlk_ecc9_client_created=1673829175;lDlk_ecc9_auth=ef18YFNYII0asASPE2u3U3ONRNbDuqTWo7sjRti9VkzdZlSFHETzOce8M877vlXg;lDlk_ecc9_connect_login=1;lDlk_ecc9_st_p=662770%7C1673829595%7Cdaec851af652b5d3c0199aabc791c7b5;lDlk_ecc9_visitedfid=202D81D168D147D51D206D178D98D27D100;lDlk_ecc9_viewid=tid_13957193;lDlk_ecc9_sid=CkKWXF;lDlk_ecc9_lip=117.163.248.13%2C1673870449;lDlk_ecc9_ulastactivity=d7e0Jr%2B9TDmtxrJE2j8MVjtkAPIeX18rnTbBp4ZnRjSeb8U5qjDz;lDlk_ecc9_home_diymode=1;lDlk_ecc9_lastact=1673948276%09plugin.php%09"
    }
    res = requests.post(url=url, data=data, headers=headers)
    try:
        json = res.json()
        if (json['status'] == 1):
            # seccess
            print(user['name'] + " ---> " + "签到成功" + "\n")
            msg += user['name'] + "|" + str(json['data']['days']) + "|" + str(json['data']['modays']) + "|" + str(
                json['data']['reward']) + "|5000|" + "seccess" + "\n\n"
        else:
            # err
            print(user['name'] + " ---> " + str(json['msg']) + "\n")
            msg += user['name'] + "|||||" + str(json['msg']) + "\n\n"

    except Exception as e:
        print(user['name'] + " ---> " + "json err" + "\n")
        msg += user['name'] + "|||||" + "json err" + "\n\n"

    print("-------------------------------------------\n")


main()

print("🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉")

notify.send("精易论坛", msg)
